import random
import string
from datetime import datetime
import mysql.connector

config = {
    'user': 'root',
    'password': '111111',
    'host': 'localhost',
    'database': 'vue_test',
    'raise_on_warnings': True
}


def generate_random_string(length=32):
    characters = string.ascii_letters + string.digits  # 组合字母和数字
    random_string = ''.join(random.choice(characters) for _ in range(length))
    return random_string

def generate_random_digits(length=32):
    digits = string.digits  # 组合字母和数字
    random_string = ''.join(random.choice(digits) for _ in range(length))
    return random_string

def doInsert():
    global cursor, cnx
    try:
        event_datetime = datetime.now()
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor()
        insert_query = "INSERT INTO sys_user (id,name, password,create_time,update_time,status) VALUES ( %s, %s, %s, %s, %s,%s)"
        for i in range(1, 2000000):
            pk = generate_random_string()
            password = generate_random_digits()
            data = (pk, "user" + pk, password, event_datetime, event_datetime, 1)
            cursor.execute(insert_query, data)

        cnx.commit()
    except mysql.connector.Error as err:
        print("error: {}".format(err))

    finally:
        cursor.close()
        cnx.close()



if __name__ == "__main__":
    doInsert()